package com.zws.cucumber.plugin.procedure;

import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
import ch.qos.logback.core.spi.ContextAware;

public class ZwsProcedurePatternLayoutEncoder extends PatternLayoutEncoder {

    public ZwsProcedurePatternLayoutEncoder(ContextAware parent, PatternLayoutEncoder other) {
        setParent(parent);
        setPattern(other.getPattern());
        setContext(other.getContext());
        setOutputPatternAsHeader(other.isOutputPatternAsHeader());
        setCharset(other.getCharset());
        start();
    }

    @Override
    public void start() {
        super.start();
        ZwsProcedureLoggerLayout patternLayout = new ZwsProcedureLoggerLayout();
        patternLayout.setContext(context);
        patternLayout.setPattern(getPattern());
        patternLayout.setOutputPatternAsHeader(outputPatternAsHeader);
        patternLayout.setPostCompileProcessor(patternLayout);
        patternLayout.start();
        this.layout = patternLayout;
    }

}
